package com.mes.material.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mes.common.core.utils.poi.ExcelUtil;
import com.mes.common.core.web.controller.BaseController;
import com.mes.common.core.web.domain.AjaxResult;
import com.mes.common.core.web.page.TableDataInfo;
import com.mes.common.log.annotation.Log;
import com.mes.common.log.enums.BusinessType;
import com.mes.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mes.material.domain.MaterialTrace;
import com.mes.material.service.IMaterialTraceService;

/**
 * 物料追溯Controller
 * 
 * @author itflash
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/material/trace")
public class MaterialTraceController extends BaseController
{
    @Autowired
    private IMaterialTraceService materialTraceService;

    /**
     * 查询物料追溯列表
     */
    @RequiresPermissions("material:trace:list")
    @GetMapping("/list")
    public TableDataInfo list(MaterialTrace materialTrace)
    {
        startPage();
        List<MaterialTrace> list = materialTraceService.selectMaterialTraceList(materialTrace);
        return getDataTable(list);
    }

    /**
     * 导出物料追溯列表
     */
    @RequiresPermissions("material:trace:export")
    @Log(title = "物料追溯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialTrace materialTrace)
    {
        List<MaterialTrace> list = materialTraceService.selectMaterialTraceList(materialTrace);
        ExcelUtil<MaterialTrace> util = new ExcelUtil<MaterialTrace>(MaterialTrace.class);
        util.exportExcel(response, list, "物料追溯数据");
    }

    /**
     * 获取物料追溯详细信息
     */
    @RequiresPermissions("material:trace:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(materialTraceService.selectMaterialTraceById(id));
    }

    /**
     * 新增物料追溯
     */
    @RequiresPermissions("material:trace:add")
    @Log(title = "物料追溯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialTrace materialTrace)
    {
        return toAjax(materialTraceService.insertMaterialTrace(materialTrace));
    }

    /**
     * 修改物料追溯
     */
    @RequiresPermissions("material:trace:edit")
    @Log(title = "物料追溯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialTrace materialTrace)
    {
        return toAjax(materialTraceService.updateMaterialTrace(materialTrace));
    }

    /**
     * 删除物料追溯
     */
    @RequiresPermissions("material:trace:remove")
    @Log(title = "物料追溯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(materialTraceService.deleteMaterialTraceByIds(ids));
    }
}
